#ifndef FILEREADER_H
#define FILEREADER_H

#include "fileHead.h"

#include <QObject>
#include <QString>
#include <QByteArray>
#include <QTcpSocket>
#include <QFileInfo>
#include <QFile>

class QHostAddress;

class FileReader : public QObject
{
    Q_OBJECT

    enum ReadState{READ_FILESINFO = 0, READ_HEAD, READ_NAME, READ_CONTENT};
public:
    explicit FileReader(QTcpSocket *socket, const QString &saveFileName, QObject *parent = 0);

    void updateProgress();
private:
    QTcpSocket *m_socket;       //接收数据套接字
    QString     m_saveFileName; //保存文件目录
    ReadState   m_readState;    //读取状态

    QFile       m_file;         //当前写入文件
    FileHead    m_head;         //每次读取的文件头

    qint64      m_totalFilesSize;   //总传输文件大小
    qint64      m_totalBytesRead;   //总读取文件大小

    qint64      m_currentFileSize;  //当前读取文件的总大小
    qint64      m_currentBytesRead; //当前读取文件已读取大小

    qint32      m_totalFilesNumber; //总待读取文件数
    qint32      m_readFilesNumber;  //已读取文件数

    QString     m_readFileName;
signals:

private:
    void readFail(const QString &failInfo);
    void readOk();
public slots:
    void onReadyRead();
};

#endif // FILEREADER_H
